package com.anolesoft.amljmes.fortysix.service.mapper;

import com.anolesoft.amljmes.fortysix.dto.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;
@Mapper
public interface MesBzzZcbldmxServiceMapper {
    @SelectProvider(type = MesBzzZcbldmxServiceMapper.createSQL1.class, method = "queryZcbldmx")
    List<MesBzzZcbldmxDto> queryZcbldmx(String bldobjuid);
    public static class createSQL1 {
        public static String queryZcbldmx(@Param("bldobjuid") String bldobjuid) {
            return new SQL() {
                {
                    StringBuilder sql = new StringBuilder();
                    sql.append(" t.objuid,\n" +
                            "       t.bldobjuid,\n" +
                            "       t.ptdmxid,\n" +
                            "       t.name,\n" +
                            "       t.model,\n" +
                            "       t.danwei,\n" +
                            "       t.bili,\n" +
                            "       t.danjishu,\n" +
                            "       t.quejianshu,\n" +
                            "       t.zerendanwei,\n" +
                            "       t.beizhu,\n" +
                            "       t.ptdid,\n" +
                            "       t.state,\n" +
                            "       a.name          shenqingren,\n" +
                            "       t.shenqing_time,\n" +
                            "       t.shenpi_state,\n" +
                            "       e.name          shenpiren,\n" +
                            "       t.shenpi_time,\n" +
                            "       t.zhuxiaotujing,\n" +
                            "       p.part_drawing_no\n" +
                            "  from mes_bzz_zcbldmx t\n" +
                            "  left join stf_employee e\n" +
                            "    on t.shenpiren = e.objuid\n" +
                            "  left join stf_employee a\n" +
                            "    on t.shenqingren = a.objuid\n" +
                            "  left join mes_bzz_ptdmx p\n" +
                            "    on t.ptdmxid = p.objuid\n" +
                            "  where bldobjuid in (");
                    sql.append("'" + bldobjuid + "'");
                    sql.append(")");
                    SELECT(sql.toString());
                }
            }.toString();
        }
    }

    @SelectProvider(type = MesBzzZcbldmxServiceMapper.createSQL2.class, method = "queryBindYjd")
    List<MesBzzBindDto> queryBindYjd(String yijiaodanhao);
    public static class createSQL2 {
        public static String queryBindYjd(@Param("yijiaodanhao") String yijiaodanhao) {
            return new SQL() {
                {
                    StringBuilder sql = new StringBuilder();
                    sql.append(" * from plan_goods_bind where yijiaodanhao in (" );
                    sql.append(yijiaodanhao);
                    sql.append(")");
                    SELECT(sql.toString());
                }
            }.toString();
        }
    }

    @SelectProvider(type = MesBzzZcbldmxServiceMapper.createSQL3.class, method = "queryBindBjd")
    List<MesBzzBindDto> queryBindBjd(String bujiandanhao);
    public static class createSQL3 {
        public static String queryBindBjd(@Param("bujiandanhao") String bujiandanhao) {
            return new SQL() {
                {
                    StringBuilder sql = new StringBuilder();
                    sql.append(" * from plan_goods_bind where bujiandanhao in (" );
                    sql.append(bujiandanhao);
                    sql.append(")");
                    SELECT(sql.toString());
                }
            }.toString();
        }
    }

    @Update("update  mes_bzz_fcfhjh set state=4 " +
            "where qualified_label_number=#{qualifiedLabelNumber, jdbcType=VARCHAR} " +
            "and state =0 and plan_type in (0,1) " )
    int updateStateZx(String qualifiedLabelNumber);
    @Update("update mes_bzz_fcfhjh set shuliang=shuliang-#{bangdingshuliang, jdbcType=NUMERIC} " +
            "where qualified_label_number=#{qualifiedLabelNumber, jdbcType=VARCHAR} " +
            "and state =0" )
    int updateNumJs(BudengyuDto bdy);

    // 生成转场保留单
    @Insert("insert into mes_bzz_zcbldmx" +
            "(bldobjuid, ptdmxid, name," +
            " model, danwei, bili," +
            " danjishu, quejianshu, zerendanwei," +
            " beizhu, ptdid)" +
            "values " +
            "(#{bldobjuid, jdbcType=VARCHAR},#{ptdmxid, jdbcType=VARCHAR},#{name, jdbcType=VARCHAR}," +
            "#{model, jdbcType=VARCHAR},#{danwei, jdbcType=VARCHAR},#{bili, jdbcType=VARCHAR}," +
            "#{danjishu, jdbcType=NUMERIC},#{quejianshu, jdbcType=NUMERIC},#{zerendanwei, jdbcType=VARCHAR}," +
            "#{beizhu, jdbcType=VARCHAR},#{ptdid, jdbcType=VARCHAR})")
    int addMesBzzZcbldmx(MesBzzZcbldmxDto inFoDtoParam);

    @Update("update mes_bzz_zcbldmx set beizhu=#{beizhu, jdbcType=VARCHAR} " +
            "where objuid=#{objuid, jdbcType=VARCHAR}" )
    int updateZcbldBz(newDto dto);

//    @SelectProvider(type = MesBzzZcbldmxServiceMapper.createSQL4.class, method = "queryBindYjBjd")
//    List<MesBzzBindDto> queryBindYjBjd(String ptdObj);
//    public static class createSQL4 {
//        public static String queryBindYjBjd(@Param("ptdObj") String ptdObj) {
//            return new SQL() {
//                {
//                    StringBuilder sql = new StringBuilder();
//                    sql.append(" * from plan_goods_bind where ptd_obj in (" );
//                    sql.append(ptdObj);
//                    sql.append(")");
//                    SELECT(sql.toString());
//                }
//            }.toString();
//        }
//    }

//    @Select("select t.*,\n" +
//            "       a.yijiaodanwei,\n" +
//            "       e.name          yijiaoren,\n" +
//            "       a.jieshoudanwei,\n" +
//            "       c.name          jieshoudaibiao,\n" +
//            "       a.jiaci,\n" +
//            "       b.drawing_no,\n" +
//            "       b.quantity,\n" +
//            "       b.customer\n" +
//            "  from mes_bzz_zcbldmx t\n" +
//            "  left join mes_bzz_zcbld a\n" +
//            "    on t.bldobjuid = a.objuid\n" +
//            "  left join mes_bzz_ptd b\n" +
//            "    on t.ptdid = b.objuid\n" +
//            "  left join stf_employee e\n" +
//            "    on a.yijiaoren = e.objuid\n" +
//            "  left join stf_employee c\n" +
//            "    on a.jieshoudaibiao = c.objuid\n" +
//            " where t.ptdid = #{objuid, jdbcType = VARCHAR}\n")
    @Select("select t.bili,\n" +
            "       t.danjishu,\n" +
            "       t.quejianshu,\n" +
            "       t.zerendanwei,\n" +
            "       a.yijiaodanwei,\n" +
            "       e.name             yijiaoren,\n" +
            "       a.jieshoudanwei,\n" +
            "       c.name             jieshoudaibiao,\n" +
            "       a.jiaci,\n" +
            "       f.part_drawing_no  drawing_no,\n" +
            "       f.affiliation,\n" +
            "       f.matched_quantity,\n" +
            "       b.quantity,\n" +
            "       b.customer,\n" +
            "       b.proportion,\n" +
            "       b.batch,\n" +
            "       g.xianghao,\n" +
            "       g.bujiandanhao,\n" +
            "       y.name jianyanren,\n" +
            "       z.name bangdingren, " +
            "       b.model,\n" +
            "       f.name,\n" +
            "       f.danwei,\n" +
            "       b.supporting_order_no\n" +
            "  from mes_bzz_ptd b\n" +
            "  left join plan_goods_bind g\n" +
            "    on b.objuid = g.ptd_obj\n" +
            "  left join mes_bzz_ptdmx f\n" +
            "    on g.ptdmx_obj  = f.objuid\n" +
            "    left join mes_bzz_zcbldmx t\n" +
            "    on t.ptdid = b.objuid\n" +
            "  left join mes_bzz_zcbld a\n" +
            "    on t.bldobjuid = a.objuid\n" +
            "  left join stf_employee e\n" +
            "    on a.yijiaoren = e.objuid\n" +
            "  left join stf_employee c\n" +
            "    on a.jieshoudaibiao = c.objuid\n" +
            "  left join stf_employee z\n" +
            "    on g.bangdingren = z.objuid\n" +
            "  left join stf_employee y\n" +
            "    on g.jianyanren = y.objuid\n" +
            "  where b.objuid = #{objuid, jdbcType = VARCHAR}\n")
    List<YjBjDto> queryBindYjBjd(@Param("objuid") String objuid);
}
